home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Description:
- // Functions called from "PaintEffectsToPoly".
- //
-
- // Description:
- // return the full path to the passed in filename
- proc string getPaintEffectsFilename( string $fname )
- {
- string $outPath = $fname;
- if( filetest( "-r", $outPath ) ){
- return $outPath;
- }
- string $visorBase = `getenv "MAYA_LOCATION"`;
- if ($visorBase != "") {
- // Set the brushImage directory path appropriately.
- $outPath = ($visorBase + "/brushImages/" + $fname);
- if( filetest( "-r", $outPath ) ){
- return $outPath;
- }
- }
-
- return $fname; // can't find file in brushImages dir, so simply return the original name
- }
-
- proc string getShaderMaterialInfo( string $shadingGroup ){
- string $con[] = `listConnections $shadingGroup`;
- int $i;
- for( $i=0; $i < size( $con ); $i++ ){
- if( "materialInfo" == nodeType( $con[$i] ) ){
- return( $con[$i] );
- }
- }
- return "";
- }
-
-
- proc copyRamp(string $source, string $sourceAttr, string $target, string $targetAttr, int $isColor, float $scale){
- // for now we assume that source has more entries than target does
- string $sourceBase = ($source + "." + $sourceAttr);
- string $targetBase = ($target + "." + $targetAttr);
- int $numEntries = `getAttr -s $sourceBase`;
- int $i, $ival;
- float $fval;
- for( $i = 0; $i < $numEntries; $i++ ){
- string $sB = ($sourceBase + "["+$i+"]."+$sourceAttr);
- string $tB = ($targetBase + "["+$i+"]."+$targetAttr);
- $fval = getAttr($sB + "_Position");
- $ival = getAttr($sB + "_Interp");
- setAttr ($tB + "_Position") $fval;
- setAttr ($tB + "_Interp") $ival;
- if( $isColor){
- $fval = getAttr($sB + "_ColorR");
- setAttr ($tB + "_ColorR") ($fval * $scale);
- $fval = getAttr($sB + "_ColorG");
- setAttr ($tB + "_ColorG") ($fval * $scale);
- $fval = getAttr($sB + "_ColorB");
- setAttr ($tB + "_ColorB") ($fval * $scale);
- } else {
- $fval = getAttr($sB + "_FloatValue");
- setAttr ($tB + "_FloatValue") ($fval * $scale);
- }
- }
- }
-
- proc createAndAssignShader(string $shaderName, float $color1[], float $color2[],
- float $incand[], float $specularColor[], float $specular, float $specularPower,
- float $glowIntensity,
- float $translucence, float $transparency[], float $softness,
- int $texType, int $colorTex, int $opTex, string $texName,
- float $texColor1[], float $texColor2[], float $smear, float $smearU, float $smearV,
- float $fractalRatio, float $fractalAmplitude, float $fractalThreshold,
- float $repeatU, float $repeatV, float $offsetU, float $offsetV,
- float $reflectivity, int $textureSpecular, int $isFlat, string $brush,
- string $mesh )
-
- {
- // create shader to match rendering by brush
- float $spec[3];
- $spec[0] = $specularColor[0] * $specular;
- $spec[1] = $specularColor[1] * $specular;
- $spec[2] = $specularColor[2] * $specular;
- int $hasSpecular = ( $spec[0] > 0.05 || $spec[1] > 0.05 || $spec[2] > 0.05 );
- int $doSoftness = ($softness < -0.05 || $softness > 0.1 );
- int $doSmear = ($smearU > 0.01 || $smearV > 0.01 );
- int $hasIncand = ($incand[0] > 0.01 || $incand[1] > 0.01 || $incand[2] > 0.01 );
- int $doReflection = ($reflectivity > 0.05 );
- float $colorDif = abs($color1[0] - $color2[0]) + abs($color1[1] - $color2[1]) + abs($color1[2] - $color2[2]);
- int $colorRamp = ($colorDif > 0.05);
- int $softnessTexture = $doSoftness && $isFlat;
- int $opacityTex = $opTex || $softnessTexture;
- int $hasTransparency = $doSoftness || $opacityTex
- || $transparency[0] > 0.1 || $transparency[1] > 0.1 || $transparency[2] > 0.1;
-
- int $useRampShader = ($doSoftness && ($softnessTexture == 0)) || $doReflection;
- string $material;
- if( $useRampShader ){
- $material = `shadingNode -asShader -name $shaderName "rampShader"`;
- setAttr ($material + ".incandescence[0].incandescence_Color") -type double3 $incand[0] $incand[1] $incand[2];
- if( $hasTransparency ){
- setAttr ($material + ".transparency[0].transparency_Color") -type double3
- $transparency[0] $transparency[1] $transparency[2];
-
- if( $hasSpecular ){
- // paint effects modulates specular based on transparency
- setAttr ($material + ".specularColor[0].specularColor_Color") -type double3
- ((1.0-$transparency[0])*$spec[0])
- ((1.0-$transparency[1])*$spec[1])
- ((1.0-$transparency[2])*$spec[2]);
- } else {
- setAttr ($material + ".specularColor[0].specularColor_Color") -type double3 0 0 0;
- }
- if( $doSoftness && ($isFlat == 0)){
- if( $softness > 0 ){
- setAttr ($material + ".transparency[1].transparency_Color") -type double3 1.0 1.0 1.0;
- setAttr ($material + ".transparency[1].transparency_Position") 0.0;
- $softness = sqrt( $softness );
- setAttr ($material + ".transparency[0].transparency_Position") $softness;
- } else {
- setAttr ($material + ".transparency[1].transparency_Color") -type double3 1.0 1.0 1.0;
- $softness = (1+$softness);
- setAttr ($material + ".transparency[1].transparency_Position") 1.0;
- setAttr ($material + ".transparency[0].transparency_Position") ($softness * 0.95);
- }
- setAttr ($material + ".transparency[1].transparency_Interp") 1.0;
- }
- } else {
- setAttr ($material + ".specularColor[0].specularColor_Color") -type double3 $spec[0] $spec[1] $spec[2];
- }
- setAttr ($material + ".eccentricity") (1.0/sqrt($specularPower));
- setAttr ($material + ".specularity") 1.0;
- removeMultiInstance -break true ($material +".specularRollOff[1]");
- if( $doReflection ){
- copyRamp( $brush, "environment", $material, "environment", true, 1.0 );
- copyRamp( $brush, "reflectionRolloff", $material, "reflectivity", false, $reflectivity);
- }
- } else {
- $material = `shadingNode -asShader -name $shaderName "phong"`;
- setAttr ($material + ".incandescence") -type double3 $incand[0] $incand[1] $incand[2];
- if( $hasTransparency ){
- setAttr ($material + ".transparency") -type double3
- $transparency[0] $transparency[1] $transparency[2];
-
- if( $hasSpecular ){
- // paint effects modulates specular based on transparency
- setAttr ($material + ".specularColor") -type double3
- ((1.0-$transparency[0])*$spec[0])
- ((1.0-$transparency[1])*$spec[1])
- ((1.0-$transparency[2])*$spec[2]);
- } else {
- setAttr ($material + ".specularColor") -type double3 0 0 0;
- }
- } else {
- setAttr ($material + ".specularColor") -type double3 $spec[0] $spec[1] $spec[2];
- }
- setAttr ($material + ".cosinePower") $specularPower;
- }
-
-
- setAttr ($material + ".diffuse") (1.0 - $translucence);
- setAttr ($material + ".translucence") $translucence;
- setAttr ($material + ".translucenceDepth") 1.0;
- setAttr ($material + ".translucenceFocus") 0.0;
- setAttr ($material + ".glowIntensity") $glowIntensity;
- string $ramp;
- // if the start end colors are not the same then create a ramp to simulate this
- if( $colorRamp ){
- $ramp = `shadingNode -asTexture ramp`;
- removeMultiInstance -break true ($ramp + ".colorEntryList[2]");
- // set ramp colors to match color 1 and 2 of brush
- setAttr ($ramp+".colorEntryList[0].color") -type double3 $color1[0] $color1[1] $color1[2] ;
- setAttr ($ramp+".colorEntryList[1].color") -type double3 $color2[0] $color2[1] $color2[2] ;
- setAttr ($ramp+".colorEntryList[1].position") 1.0 ;
- if( $useRampShader ){
- connectAttr -f ($ramp+".outColor") ($material+".color[0].color_Color");
- } else {
- connectAttr -f ($ramp+".outColor") ($material+".color");
- }
- }else {
- if( $useRampShader ){
- setAttr ($material + ".color[0].color_Color") -type double3 $color1[0] $color1[1] $color1[2];
- } else {
- setAttr ($material + ".color") -type double3 $color1[0] $color1[1] $color1[2];
- }
- }
- string $tex, $texOp;
- if( $colorTex || $opacityTex ){
- int $needsTransformNode = $repeatU != 1.0 || $repeatV != 1.0 || $offsetU != 0.0 || $offsetV != 0.0;
- float $colorGain[3];
- if( $colorTex && !$colorRamp){
- $colorGain = $color1;
- } else {
- $colorGain[0] = $colorGain[1] = $colorGain[2] = 1.0;
- }
- if( $colorTex || $opTex ){
-
- if( $texType != 1 && $texType != 2 ){ // not a ramp
- if( $smear < 0.8 ){
- $doSmear = false; // transform node smear is only high frequency
- }
- if( $doSmear ){
- $needsTransformNode = true;
- }
- }
- if( $texType == 0 ){ // checker
- $tex = `shadingNode -asTexture checker`;
- if( $colorTex ){
- setAttr ($tex+".color1") -type double3 $texColor1[0] $texColor1[1] $texColor1[2];
- setAttr ($tex+".color2") -type double3 $texColor2[0] $texColor2[1] $texColor2[2];
- }
- } else if( $texType == 1 || $texType == 2){ // U or VRamp
- $tex = `shadingNode -asTexture ramp`;
- removeMultiInstance -break true ($tex + ".colorEntryList[2]");
- if( $colorTex ){
- setAttr ($tex+".colorEntryList[0].color") -type double3 $texColor2[0] $texColor2[1] $texColor2[2] ;
- setAttr ($tex+".colorEntryList[1].color") -type double3 $texColor1[0] $texColor1[1] $texColor1[2] ;
- } else {
- setAttr ($tex+".colorEntryList[0].color") -type double3 0.0 0.0 0.0 ;
- setAttr ($tex+".colorEntryList[1].color") -type double3 1.0 1.0 1.0 ;
- }
- setAttr ($tex+".colorEntryList[1].position") 1.0 ;
- if( $texType == 2 ){ // V Ramp
- setAttr ($tex + ".type") 1;
- }
- if( $doSmear ){
- setAttr ($tex + ".noiseFreq") $smear;
- setAttr ($tex + ".noise") (($smearU + $smearV) * 0.5);
- }
- } else if( $texType == 3 ){ // Fractal
- $tex = `shadingNode -asTexture fractal`;
- setAttr ($tex + ".ratio") $fractalRatio;
- setAttr ($tex + ".amplitude") $fractalAmplitude;
- setAttr ($tex + ".threshold") $fractalThreshold;
- } else if( $texType == 4 ){ // File
- $texName = getPaintEffectsFilename( $texName );
- if( size( $texName ) > 0 ){
- $tex = `shadingNode -asTexture file`;
- setAttr ($tex + ".fileTextureName") -type "string" $texName;
- if( $opTex ){
- // see if the image has an alpha channel
- int $hasAlpha = `getAttr ($tex + ".fileHasAlpha")`;
-
- if( !$hasAlpha ){
- // if there is not an alpha channel don't connect alpha out
- $opTex = false;
- if($softnessTexture == false){
- $opacityTex = false;
- }
- if( !$colorTex ){
- // we can delete the texure if there is no use for color
- $needsTransformNode = false;
- delete $tex;
- }
- }
- }
- } else {
- $colorTex = false;
- $opTex = false;
- if($softnessTexture == false){
- $opacityTex = false;
- }
- $needsTransformNode = false;
- }
- }
- if( $needsTransformNode ){
- string $tform = `shadingNode -asUtility place2dTexture`;
- setAttr ($tform + ".repeatU" ) $repeatV;
- setAttr ($tform + ".repeatV" ) $repeatU;
- setAttr ($tform + ".offsetU" ) $offsetV;
- setAttr ($tform + ".offsetV" ) $offsetU;
- if( $doSmear && $texType != 1 && $texType != 2 ){
- setAttr ($tform + ".noiseU" ) ($smearV * 0.2);
- setAttr ($tform + ".noiseV" ) ($smearU * 0.2);
- }
- connectAttr ($tform + ".outUV") ($tex + ".uv");
- connectAttr ($tform + ".outUvFilterSize") ( $tex + ".uvFilterSize" );
- if( $texType == 4 ){ // file textures need these extra connections
- connectAttr -f ($tform + ".coverage") ($tex + ".coverage");
- connectAttr -f ($tform + ".translateFrame") ($tex + ".translateFrame");
- connectAttr -f ($tform + ".rotateFrame") ($tex + ".rotateFrame");
- connectAttr -f ($tform + ".mirrorU") ($tex + ".mirrorU");
- connectAttr -f ($tform + ".mirrorV") ($tex + ".mirrorV");
- connectAttr -f ($tform + ".stagger") ($tex + ".stagger");
- connectAttr -f ($tform + ".wrapU") ($tex + ".wrapU");
- connectAttr -f ($tform + ".wrapV") ($tex + ".wrapV");
- connectAttr -f ($tform + ".repeatUV") ($tex + ".repeatUV");
- connectAttr -f ($tform + ".offset") ($tex + ".offset");
- connectAttr -f ($tform + ".rotateUV") ($tex + ".rotateUV");
- connectAttr -f ($tform + ".noiseUV") ($tex + ".noiseUV");
- connectAttr -f ($tform + ".vertexUvOne") ($tex + ".vertexUvOne");
- connectAttr -f ($tform + ".vertexUvTwo") ($tex + ".vertexUvTwo");
- connectAttr -f ($tform + ".vertexUvThree") ($tex + ".vertexUvThree");
- connectAttr -f ($tform + ".vertexCameraOne") ($tex + ".vertexCameraOne");
- }
- }
-
- if( $colorTex ){
- if( $texType > 2 ){
- $texColor1[0] *= $colorGain[0];
- $texColor1[1] *= $colorGain[1];
- $texColor1[2] *= $colorGain[2];
- $texColor2[0] *= $colorGain[0];
- $texColor2[1] *= $colorGain[1];
- $texColor2[2] *= $colorGain[2];
- setAttr ($tex + ".colorOffset") -type double3 $texColor2[0] $texColor2[1] $texColor2[2];
- $colorGain[0] = $texColor1[0] -$texColor2[0];
- $colorGain[1] = $texColor1[1] -$texColor2[1];
- $colorGain[2] = $texColor1[2] -$texColor2[2];
- }
- if( $colorRamp ){
- connectAttr ($tex + ".outColor") ($ramp + ".colorGain");
- } else {
- if( $useRampShader ){
- connectAttr ($tex + ".outColor") ($material + ".color[0].color_Color");
- }else{
- connectAttr ($tex + ".outColor") ($material + ".color");
- }
- }
- setAttr ($tex + ".colorGain") -type double3 $colorGain[0] $colorGain[1] $colorGain[2];
- }
- }
- $texOp = $tex;
- if( $softnessTexture ){
- $softTex = `shadingNode -asTexture ramp`;
- removeMultiInstance -break true ($softTex + ".colorEntryList[2]");
- setAttr ($softTex+".colorEntryList[0].color") -type double3 1.0 1.0 1.0 ;
- setAttr ($softTex+".colorEntryList[1].color") -type double3
- $transparency[0] $transparency[1] $transparency[2];
- setAttr ($softTex+".colorEntryList[0].position") 0.0 ;
- setAttr ($softTex+".colorEntryList[1].position") $softness ;
- setAttr ($softTex + ".type") 1;
- setAttr ($softTex + ".interpolation") 4;
- string $tform = `shadingNode -asUtility place2dTexture`;
- setAttr ($tform + ".repeatU" ) 2;
- setAttr ($tform + ".mirrorU" ) 1;
- connectAttr ($tform + ".outUV") ($softTex + ".uv");
- connectAttr ($tform + ".outUvFilterSize") ( $softTex + ".uvFilterSize" );
- if( $opTex ){
- if( $texType == 4 ){
- connectAttr -f ($texOp + ".outTransparency")
- ($softTex+".colorEntryList[1].color");
- } else {
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputX");
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputY");
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputZ");
- connectAttr -f ($reverse + ".output")
- ($softTex+".colorEntryList[1].color");
- }
- }
- $texOp = $softTex;
- }
- if( $opacityTex ){
- string $outAttr;
- if( $softnessTexture ) {
- $outAttr = ($texOp + ".outColor");
- } else if( $texType == 4 ){
- // only file texture has outTransparency
- $outAttr = ($texOp + ".outTransparency");
- } else {
- // We need to create a reverse node to convert alpha to transparency.
- // Hopefully the fan out here will not result in extra evaluations of
- // the texture per sample.
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputX");
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputY");
- connectAttr -f ($texOp + ".outAlpha") ($reverse + ".inputZ");
- $outAttr = ($reverse + ".output");
- }
- if( $useRampShader ){
- connectAttr $outAttr ($material + ".transparency[0].transparency_Color");
- }else{
- connectAttr $outAttr ($material + ".transparency");
- }
- }
- }
- if( $hasSpecular && ($opacityTex || ($colorTex && $textureSpecular))){
- // modulate specular based on transparency
- string $mult;
- if( $opacityTex ){
- $mult = `shadingNode -asUtility multiplyDivide`;
- if( $softnessTexture ){
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outColor") ($reverse + ".input");
- connectAttr -f ($reverse + ".output") ($mult + ".input2");
- }else if( $texType == 4 ){
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outTransparency") ($reverse + ".input");
- connectAttr -f ($reverse + ".output") ($mult + ".input2");
- } else {
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2X");
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2Y");
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2Z");
- }
-
- setAttr ($mult + ".input1X") ($specularColor[0]*$specular);
- setAttr ($mult + ".input1Y") ($specularColor[1]*$specular);
- setAttr ($mult + ".input1Z") ($specularColor[2]*$specular);
- }
- if( $colorTex && $textureSpecular ){
- string $mult2 = `shadingNode -asUtility multiplyDivide`;
- connectAttr -f ($tex + ".outColor") ($mult2 + ".input2");
- setAttr ($mult2 + ".input1X") ($specularColor[0]*$specular);
- setAttr ($mult2 + ".input1Y") ($specularColor[1]*$specular);
- setAttr ($mult2 + ".input1Z") ($specularColor[2]*$specular);
- if( $opacityTex ){
- // combine opacity and color mults together
- string $mult3 = `shadingNode -asUtility multiplyDivide`;
- connectAttr -f ($mult + ".output") ($mult3 + ".input1");
- connectAttr -f ($mult2 + ".output") ($mult3 + ".input2");
- $mult = $mult3;
- } else {
- $mult = $mult2;
- }
- }
- if( $useRampShader ){
- connectAttr -f ($mult + ".output") ($material + ".specularColor[0].specularColor_Color");
- } else {
- connectAttr -f ($mult + ".output") ($material + ".specularColor");
- }
- }
- if( $hasIncand && $opacityTex ){
- // modulate specular based on transparency
- string $mult;
- if( $opacityTex ){
- $mult = `shadingNode -asUtility multiplyDivide`;
- if( $softnessTexture ){
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outColor") ($reverse + ".input");
- connectAttr -f ($reverse + ".output") ($mult + ".input2");
- }else if( $texType == 4 ){
- string $reverse = `shadingNode -asUtility reverse`;
- connectAttr -f ($texOp + ".outTransparency") ($reverse + ".input");
- connectAttr -f ($reverse + ".output") ($mult + ".input2");
- } else {
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2X");
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2Y");
- connectAttr -f ($texOp + ".outAlpha") ($mult + ".input2Z");
- }
-
- setAttr ($mult + ".input1X") ($incand[0]);
- setAttr ($mult + ".input1Y") ($incand[1]);
- setAttr ($mult + ".input1Z") ($incand[2]);
- }
- if( $useRampShader ){
- connectAttr -f ($mult + ".output") ($material + ".incandescence[0].incandescence_Color");
- } else {
- connectAttr -f ($mult + ".output") ($material + ".incandescence");
- }
- }
-
- // create and assign shading group
- $sg = `sets -renderable true -noSurfaceShader true -empty -name ($material + "SG")`;
- defaultNavigation
- -connectToExisting
- -source $material
- -destination $sg;
- select -r $mesh;
- hyperShade -assign $sg;
-
- if( $opacityTex && !$useRampShader ){
- // set up connections for combined channels texturing
- string $matInfo = getShaderMaterialInfo( $sg );
- if( $matInfo != ""){
- setAttr ($matInfo + ".texturePlug") -type "string" ($material + ".outColor");
- connectAttr -f ($material + ".message") ($matInfo + ".texture[0]");
- }
- }
- }
-
- //
- // Procedure Name:
- // doPaintEffectsToPoly
- //
- // Description:
- // This is the actual function that gets called from "PaintEffectsToPoly"
- // option box.
- //
- // Input Arguments:
- // ConstructionHistory 0 = OFF, 1 = ON
- // VertexColorMode 0 = NONE, 1 = Color, 2 = Illuminated
- // QuadOutput 0 = triangles, 1 = quads
- //
- // Return Value:
- // None.
- //
- //
- global proc int doPaintEffectsToPoly( int $constructionHistory, int $vertColorMode,
- int $quadOutput, int $hideStrokes, int $polyLimit)
- {
- int $status = 0;
-
- string $strokes[] = `ls -sl -dag -type stroke`;
- int $len = size($strokes);
- if( $len < 1 ){
- error( "Select one or more strokes to tessellate." );
- return $status;
- }
- string $newMeshes[];
- string $selectedMeshes[];
- int $meshCount = 0;
- int $i;
- string $perspCameras[] = `listCameras -p`;
-
- // always create shaders with textures.. originally we didn't do this if colorPerVertex was used.
- int $createTexturedShaders = true;
-
- for($i = 0; $i < $len; $i++) {
- string $stroke = $strokes[$i];
-
- int $vis = `getAttr ($stroke + ".visibility")`;
- if (!$vis){
- continue;
- }
- // get the stroke's brush
- string $attr = $stroke + ".brush";
- string $result = `connectionInfo -sfd $attr`;
- if( size( $result ) < 1 ){
- continue; // skip if stroke has no brush
- }
- string $buffer[];
- int $num = `tokenize $result "." $buffer`;
- string $brush = $buffer[0];
- int $brushType = getAttr( $brush + ".brushType" );
- int $tubes = getAttr( $brush + ".tubes" );
- int $hardEdges = getAttr( $brush + ".hardEdges" );
-
- setAttr ($stroke + ".meshVertexColorMode") $vertColorMode;
- setAttr ($stroke + ".meshQuadOutput") $quadOutput;
- setAttr ($stroke + ".meshHardEdges") $hardEdges;
- setAttr ($stroke + ".meshPolyLimit") $polyLimit;
-
- // set up mesh parent xform
- string $meshParent = `createNode transform -name ($brush+"MeshGroup") `;
-
- // setup mainMesh
- string $mainParent = `createNode transform -name ($brush+"Main") -p $meshParent`;
- string $mainMesh = `createNode mesh -n ($brush+"MainShape") -p $mainParent`;
-
-
- // make sure we get the full path, since a name that's unique now
- // might not be unique by the time we're done
- $selectedMeshes = `selectedNodes`;
- $newMeshes[$meshCount] = $selectedMeshes[0];
-
- $meshCount++;
- connectAttr ($stroke + ".worldMainMesh[0]") ($mainMesh + ".inMesh");
- float $incand1[] = `getAttr ($brush + ".incandescence1")`;
- float $incand2[] = `getAttr ($brush + ".incandescence2")`;
- float $transp1[] = `getAttr ($brush + ".transparency1")`;
- float $transp2[] = `getAttr ($brush + ".transparency2")`;
- float $transp[3];
- float $softness = getAttr( $brush + ".softness" );
- float $glow = getAttr( $brush + ".glow" );
- float $shaderGlow = getAttr( $brush + ".shaderGlow" );
- float $glowIntensity = $glow + $shaderGlow;
- float $fractalAmplitude = getAttr( $brush + ".fractalAmplitude" );
- float $fractalRatio = getAttr( $brush + ".fractalRatio" );
- float $fractalThreshold = getAttr( $brush + ".fractalThreshold" );
- if( $tubes ){
- $transp[0] = ($transp1[0] + $transp2[0]) * 0.5;
- $transp[1] = ($transp1[1] + $transp2[1]) * 0.5;
- $transp[2] = ($transp1[2] + $transp2[2]) * 0.5;
- $incand1[0] = ($incand1[0] + $incand2[0]) * 0.5;
- $incand1[1] = ($incand1[1] + $incand2[1]) * 0.5;
- $incand1[2] = ($incand1[2] + $incand2[2]) * 0.5;
- } else {
- $transp = $transp1;
- }
- int $textureSpecular = false;
- if( $brushType < 4 ){
- // When converting stamp type brushes to mesh
- // we do not usually want low levels of softness
- // and transparency.
- if( $softness > -0.3 && $softness < 0.3 ){
- $softness = 0.0;
- }
- if( $transp[0] < 0.2 ){
- $transp[0] = 0.0;
- }
- if( $transp[1] < 0.2 ){
- $transp[1] = 0.0;
- }
- if( $transp[2] < 0.2 ){
- $transp[2] = 0.0;
- }
- // Stamp brushes apply any color textures to specular
- // as well.
- $textureSpecular = true;
- }
-
- float $specularColor[] = `getAttr ($brush + ".specularColor")`;
- float $specularPower = `getAttr ($brush + ".specularPower")`;
- if( $specularPower < 2.0 ){
- $specularPower = 2.0; // minimum on phong node
- }
- int $texType = `getAttr($brush + ".textureType")`;
- int $colorTex = `getAttr($brush + ".mapColor")`;
- int $opacityTex = `getAttr($brush + ".mapOpacity")`;
- float $repeatU = `getAttr($brush + ".repeatU")`;
- float $repeatV = `getAttr($brush + ".repeatV")`;
- float $offsetU = `getAttr($brush + ".offsetU")`;
- float $offsetV = `getAttr($brush + ".offsetV")`;
- string $texName = `getAttr($brush + ".imageName")`;
-
- int $linkCamera = `getAttr( $brush + ".forwardTwist" )`;
- float $flatness1 = `getAttr($brush + ".flatness1" )`;
- float $flatness2 = `getAttr($brush + ".flatness2" )`;
- int $isFlat;
- if( $brushType < 4 ){
- $isFlat = $flatness1 > 0.7 && (($tubes==0) || $flatness2 > 0.7);
- } else {
- $isFlat = $flatness1 > 0.999 && (($tubes==0) || $flatness2 > 0.999);
- }
-
- if( !$linkCamera && ($brushType < 4 ) && $opacityTex ){
- // to better simulate the 2D map method we use forwardTwist
- // when converting stamp style brushes. TstrokeShape has the
- // same checks as the code below and sets forward twist on
- // during the pfxToPoly call.
- int $mapMethod = `getAttr($brush + ".mapMethod" )`;
- if( $mapMethod == 2 ){
- if( $flatness1 < 0.05 && (($tubes==0) || $flatness2 < 0.05 )){
- $linkCamera = true;
- $isFlat = true;
- }
- }
- }
-
- if( $createTexturedShaders ){
- // create shader to match branch rendering by brush
- float $color1[] = `getAttr ($brush + ".color1")`;
- float $color2[] = $color1;
- if( $tubes ){
- $color2 = `getAttr ($brush + ".color2")`;
-
- // We try to mimick depth shadow effect
- // by darkening color1.
- float $depthShadow = `getAttr($brush + ".depthShadow")`;
- if( $depthShadow > 0.05 ){
- float $lengthMax = `getAttr($brush + ".lengthMax")`;
- float $depthShadowDepth = `getAttr($brush + ".depthShadowDepth")`;
- float $weight = $depthShadowDepth/$lengthMax;
- if( $weight > 0 ){
- if( $weight < 1.0 ){
- $depthShadow *= $weight;
- }
- $depthShadow = 1.0-$depthShadow;
- $color1[0] *= $depthShadow;
- $color1[1] *= $depthShadow;
- $color1[2] *= $depthShadow;
- }
- }
- }
- float $specular = `getAttr ($brush + ".specular")`;
- float $translucence = `getAttr ($brush + ".translucence")`;
- float $smearU = `getAttr ($brush + ".smearU")`;
- float $smearV = `getAttr ($brush + ".smearV")`;
- float $smear = `getAttr ($brush + ".smear")`;
- float $texColor1[] = `getAttr ($brush + ".texColor1")`;
- float $texColor2[] = `getAttr ($brush + ".texColor2")`;
- float $reflectivity = 0.0;
- if( $brushType == 5 ){ // mesh brush
- $reflectivity = `getAttr ($brush + ".branchReflectivity")`;
- }
-
- createAndAssignShader(($brush + "Shader"), $color1, $color2,
- $incand1, $specularColor, $specular, $specularPower, $glowIntensity,
- $translucence, $transp, $softness,
- $texType, $colorTex, $opacityTex, $texName,
- $texColor1, $texColor2, $smear, $smearU, $smearV,
- $fractalRatio, $fractalAmplitude, $fractalThreshold,
- $repeatU, $repeatV, $offsetU, $offsetV,
- $reflectivity, $textureSpecular, $isFlat, $brush, $mainMesh );
-
- } else {
- // color per vertex.. create simple surface shader
- string $material = `shadingNode -asShader "lambert"`;
- // create and assign shading group
- string $sg = `sets -renderable true -noSurfaceShader true -empty -name ($material + "SG")`;
- defaultNavigation
- -connectToExisting
- -source $material
- -destination $sg;
- select -r $mainMesh;
- hyperShade -assign $sg;
- }
-
- if( !$constructionHistory ){
- delete -ch $mainMesh;
- }
-
-
-
- // setup leafMesh
- int $leaves = ($tubes && getAttr( $brush + ".leaves" ));
- if( $leaves ){
- if( getAttr( $brush + ".leafForwardTwist" )) {
- $linkCamera = true;
- }
- int $useBranch = `getAttr($brush + ".leafUseBranchTex")`;
- float $flatness = `getAttr($brush + ".leafFlatness" )`;
- $isFlat = $flatness > 0.999
- || ($brushType < 4 && $flatness > 0.7);
- if( !$linkCamera && ($brushType < 4 ) && !$useBranch ){
- // to better simulate the 2D map method we use forwardTwist
- // when converting stamp style brushes. TstrokeShape has the
- // same checks as the code below and sets forward twist on
- // during the pfxToPoly call.
- if( $flatness < 0.3 ){
- string $tName = `getAttr ($brush + ".leafImage")`;
- if( size( $tName ) > 0 ){
- $linkCamera = true;
- $isFlat = true;
- }
- }
- }
- string $leafParent = `createNode transform -name ($brush+"Leaf") -p $meshParent`;
- string $leafMesh = `createNode mesh -name ($brush+"LeafShape") -p $leafParent`;
-
- // make sure we get the full path, since a name that's unique now
- // might not be unique by the time we're done
- $selectedMeshes = `selectedNodes`;
- $newMeshes[$meshCount] = $selectedMeshes[0];
-
- $meshCount++;
- connectAttr ($stroke + ".worldLeafMesh[0]") ($leafMesh + ".inMesh");
- if( $createTexturedShaders ){
- // create shader to match leaf rendering by brush
- float $color1[] = `getAttr ($brush + ".leafColor1")`;
- float $color2[] = `getAttr ($brush + ".leafColor2")`;
- float $specular = `getAttr ($brush + ".leafSpecular")`;
- float $translucence = `getAttr ($brush + ".leafTranslucence")`;
- int $tType = $texType;
- int $colTex = $colorTex;
- int $opTex = $opacityTex;
- string $tName = $texName;
- float $repU = $repeatU;
- float $repV = $repeatV;
- float $offU = $offsetU;
- float $offV = $offsetV;
- if( !$useBranch ){
- $tName = `getAttr ($brush + ".leafImage")`;
- if( size( $tName ) > 0 ){
- $colTex = true;
- $opTex = true;
- $tType = 4;
- $repU = 1.0;
- $repV = 1.0;
- $offU = 0.0;
- $offV = 0.0;
- } else {
- $colTex = false;
- $opTex = false;
- }
- }
- float $smearU = 0.0;
- float $smearV = 0.0;
- float $smear = 1.0;
- float $texColor1[3];
- float $reflectivity = 0.0;
- if( $brushType == 5 ){ // mesh brush
- $reflectivity = `getAttr ($brush + ".leafReflectivity")`;
- }
- $texColor1[0] = $texColor1[1] = $texColor1[2] = 1.0;
- $texColor2[0] = $texColor2[1] = $texColor2[2] = 0.0;
- createAndAssignShader(($brush + "LeafShader"), $color1, $color2,
- $incand1, $specularColor, $specular, $specularPower, $glowIntensity,
- $translucence, $transp, $softness,
- $tType, $colTex, $opTex, $tName,
- $texColor1, $texColor2, $smear, $smearU, $smearV,
- $fractalRatio, $fractalAmplitude, $fractalThreshold,
- $repU, $repV, $offU, $offV,
- $reflectivity, $textureSpecular, $isFlat, $brush, $leafMesh );
- } else {
- // color per vertex.. create simple surface shader
- string $material = `shadingNode -asShader "lambert"`;
- // create and assign shading group
- $sg = `sets -renderable true -noSurfaceShader true -empty -name ($material + "SG")`;
- defaultNavigation
- -connectToExisting
- -source $material
- -destination $sg;
- select -r $leafMesh;
- hyperShade -assign $sg;
- }
-
- if( !$constructionHistory ){
- delete -ch $leafMesh;
- }
- }
-
-
-
-
- // setup flowerMesh
- int $flowers = ($tubes && getAttr( $brush + ".flowers" ));
- if( $flowers ){
- if( getAttr( $brush + ".petalForwardTwist" )) {
- $linkCamera = true;
- }
- int $useBranch = `getAttr($brush + ".flowerUseBranchTex")`;
- float $flatness = `getAttr($brush + ".petalFlatness" )`;
- $isFlat = $flatness > 0.999
- || ($brushType < 4 && $flatness > 0.7);
- if( !$linkCamera && ($brushType < 4 ) && !$useBranch ){
- // to better simulate the 2D map method we use forwardTwist
- // when converting stamp style brushes. TstrokeShape has the
- // same checks as the code below and sets forward twist on
- // during the pfxToPoly call.
- if( $flatness < 0.8 ){
- string $tName = `getAttr ($brush + ".flowerImage")`;
- if( size( $tName ) > 0 ){
- $linkCamera = true;
- $isFlat = true;
- }
- }
- }
- string $flowerParent = `createNode transform -name ($brush+"Flower") -p $meshParent`;
- string $flowerMesh = `createNode mesh -name ($brush+"FlowerShape") -p $flowerParent`;
- // make sure we get the full path, since a name that's unique now
- // might not be unique by the time we're done
- $selectedMeshes = `selectedNodes`;
- $newMeshes[$meshCount] = $selectedMeshes[0];
-
- $meshCount++;
- connectAttr ($stroke + ".worldFlowerMesh[0]") ($flowerMesh + ".inMesh");
-
- if( $createTexturedShaders ){
- // create shader to match flower rendering by brush
- float $color1[] = `getAttr ($brush + ".petalColor1")`;
- float $color2[] = `getAttr ($brush + ".petalColor2")`;
- float $specular = `getAttr ($brush + ".flowerSpecular")`;
- float $translucence = `getAttr ($brush + ".flowerTranslucence")`;
- int $tType = $texType;
- int $colTex = $colorTex;
- int $opTex = $opacityTex;
- string $tName = $texName;
- float $repU = $repeatU;
- float $repV = $repeatV;
- float $offU = $offsetU;
- float $offV = $offsetV;
- if( !$useBranch ){
- $tName = `getAttr ($brush + ".flowerImage")`;
- if( size( $tName ) > 0 ){
- $colTex = true;
- $opTex = true;
- $tType = 4;
- $repU = 1.0;
- $repV = 1.0;
- $offU = 0.0;
- $offV = 0.0;
- } else {
- $colTex = false;
- $opTex = false;
- }
- }
- float $smearU = 0.0;
- float $smearV = 0.0;
- float $smear = 1.0;
- float $texColor1[3];
- float $texColor1[3];
- float $reflectivity = 0.0;
- if( $brushType == 5 ){ // mesh brush
- $reflectivity = `getAttr ($brush + ".flowerReflectivity")`;
- }
- $texColor1[0] = $texColor1[1] = $texColor1[2] = 1.0;
- $texColor2[0] = $texColor2[1] = $texColor2[2] = 0.0;
- createAndAssignShader(($brush + "FlowerShader"), $color1, $color2,
- $incand1, $specularColor, $specular, $specularPower, $glowIntensity,
- $translucence, $transp, $softness,
- $tType, $colTex, $opTex, $tName,
- $texColor1, $texColor2, $smear, $smearU, $smearV,
- $fractalRatio, $fractalAmplitude, $fractalThreshold,
- $repU, $repV, $offU, $offV,
- $reflectivity, $textureSpecular, $isFlat, $brush, $flowerMesh );
-
- } else {
- // color per vertex.. create simple surface shader
- string $material = `shadingNode -asShader "lambert"`;
- // create and assign shading group
- $sg = `sets -renderable true -noSurfaceShader true -empty -name ($material + "SG")`;
- defaultNavigation
- -connectToExisting
- -source $material
- -destination $sg;
- select -r $flowerMesh;
- hyperShade -assign $sg;
- }
-
- if( !$constructionHistory ){
- delete -ch $flowerMesh;
- }
- }
- if($hideStrokes){
- setAttr ($stroke + ".visibility") 0;
- }
- if($linkCamera && size($perspCameras) > 0){
- connectAttr -f ($perspCameras[0] + ".translate") ($stroke + ".cameraPoint");
- }
-
- }
- select -r $newMeshes;
- $status = 1;
-
- return $status;
- }
-
-
-